<?
    require_once("mvc/action/ActionForm.php");
    require_once("mvc/action/ActionMessage.php");
    require_once("mvc/action/ActionMessages.php");

    require_once("cms/newsletter/om/Newsletter.php");


    class BaseNewsletterForm extends ActionForm {

        protected $newsletter;
        protected $email;
        protected $languages;
        protected $template;

        public function __construct() {
            $this->newsletter = new Newsletter();
            $this->email = null;
            $this->languages = array();
            $this->template = null;
        }

        public function getNewsletter() {
            return $this->newsletter;
        }

        public function setNewsletter(Newsletter $newsletter) {
            $this->newsletter = $newsletter;
        }

        public function getEmail() {
            return $this->email;
        }

        public function setEmail($email) {
            $this->email = $email;
        }

        public function getLanguages() {
            return $this->languages;
        }

        public function setLanguages($languages) {
            $this->languages = $languages;
        }

        public function getTemplate() {
            return $this->template;
        }

        public function setTemplate($template) {
            $this->template = $template;
        }

        public function validate() {

            $errors = new ActionMessages();

            if(is_null($this->getNewsletter()->getSubject()) || strlen($this->getNewsletter()->getSubject()) == 0)
                $errors->add("newsletter->subject",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.subject", true)));


            if(!is_null($this->getNewsletter()->getSubject()) && strlen($this->getNewsletter()->getSubject()) > 0 && strlen($this->getNewsletter()->getSubject()) > 255)
                $errors->add("newsletter->subject",
                    new ActionMessage("errors.maxlength", true, array(
                        new ActionMessage("prompt.subject", true),
                        new ActionMessage("255", false))));


            if(is_null($this->getNewsletter()->getBody()) || strlen($this->getNewsletter()->getBody()) == 0)
                $errors->add("newsletter->body",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.body", true)));


            if(!is_null($this->getEmail()) && strlen($this->getEmail()) > 0 && !ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $this->getEmail()))
                $errors->add("email",
                    new ActionMessage("errors.email", true, new ActionMessage("prompt.email", true)));


            return $errors;
        }

    }
?>